package com.twu.biblioteca;

import java.util.Scanner;

public class BibliotecaApp {

    Book[] book = new Book[6];
    CustomerDetails[] customerDetails = new CustomerDetails[10];
    Movie[] movieDetails = new Movie[16];
    MemberLogIn memberLogIn = new MemberLogIn();
    MembershipDetails membershipDetails = new MembershipDetails();
    LibraryData libraryData = new LibraryData();

    int customerNumber=0;
    public static int choice;

    Scanner scanner = new Scanner(System.in);

    public static void main(String[] args)
    {
        BibliotecaApp bibliotecaApp=new BibliotecaApp();
        bibliotecaApp.initialise();
        bibliotecaApp.menuSelection();
    }

    public void initialise()
    {
        libraryData.getCustomerDetail(customerDetails);
        libraryData.BookList(book);
        libraryData.MovieList(movieDetails);
    }

    public void menuSelection()
    {
        Scanner scanner = new Scanner (System.in);

        System.out.println("\n****WELCOME****");
        System.out.println("1. Home\n2. Books List\n3. Movies\n4. Membership Details\n5. Log In\n6. Log Out\n7. Exit");
        choice = scanner.nextInt();
        int selection;

        switch (choice)
        {
            case 1: menuSelection();
                    break;
            case 2: libraryData.showBookList(book);
                    selection=reserve();
                    librarySelection(selection,choice);
                    break;
            case 3: libraryData.showMovieList(movieDetails);
                    selection=reserve();
                    librarySelection(selection,choice);
                    menuSelection();
                    break;
            case 4: membershipDetails.showMembershipDetails(customerNumber, customerDetails);
                    menuSelection();
                    break;
            case 5: logIn();
                    menuSelection();
            case 6: logOut();
                    menuSelection();
            case 7: System.exit(0);
        }
    }

    public void logIn()
    {
        if (customerNumber == 0){
            customerNumber = memberLogIn.checkLogIn(customerDetails);
            System.out.println("You have successfully LoggedIn!");
            menuSelection();
        }
        System.out.println("You are already Logged In!");

    }

    public void logOut()
    {
        if (customerNumber == 0){
            System.out.println("You are not Logged In!");
            return;
        }
        customerDetails[customerNumber].loggedInFlag=false;
        System.out.println("You have successfully Logged Out!");
    }

    public void librarySelection(int selection,int choice)
    {
        int articleNum;
        System.out.println("\n****Library Article Selection Menu****");
        switch (selection)
        {
            case 1 :if (customerNumber != 0)
                        break;
                    customerNumber = memberLogIn.checkLogIn(customerDetails);
                    break;
            case 2 : System.exit(0);
                     break;
            default: System.out.println("Enter a valid option!");
                     System.exit(0);
        }
        System.out.print("Enter the article number: ");
        articleNum = scanner.nextInt();

        if (choice == 2)
        {
            customerDetails[customerNumber].bookReserve(book[articleNum]);
            menuSelection();
        }
        if (choice == 3)
        {
            customerDetails[customerNumber].movieReserve(movieDetails[articleNum]);
            menuSelection();
        }
    }

    public int reserve()
    {
        System.out.println("\n1.Reserve\n2.Exit");
        int selection;
        selection = scanner.nextInt();
        return selection;
    }
}
